package com.leetcode;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

/**
 * <p>
 * 【银泰面试题】 2021.3.3 面试题
 * 传入主要业务参数包括转出账号，转入账号，转账金额，完成转出和转入账号的资金处理，该服务要确保在资金处理时转出账户的余额不会透支，金额计算准确
 * </p>
 *
 * @author: Sunny
 * @date: 2021/3/4
 * @version: v1.0.0
 */
@Slf4j
public class Transfer {

    // private String checkAmoutisEnoughRemoteService = 一个可以校验用户余额是否足够的远程服务;

    /**
     * 转出账号
     */
    private String transferToAccount;

    /**
     * 转出账号的初始金额
     */
    private BigDecimal transferToAccountAmount;

    /**
     * 转入账号
     */
    private String transferInAccount;

    /**
     * 转入账号的初始金额
     */
    private BigDecimal transferInAccountAmount;

    /**
     * 转账金额
     */
    private BigDecimal transferAmount;

    public Boolean transfer(BigDecimal transferAmount) {
        if (transferToAccountAmount.compareTo(transferAmount) < 0) {
            log.error("转账失败.");
            return false;
        }
        transferToAccountAmount = transferToAccountAmount.divide(transferAmount);
        transferInAccountAmount = transferInAccountAmount.add(transferAmount);
        return true;
    }

}
